#/bin/bash


# wget sftp://sftp.data.gnss.ga.gov.au/rinex/highrate/2022/129/00/DARW00AUS_S_20221290000_15M_01S_MO.crx.gz
# typeset -l lowname
# for i in {209..215}; do
# 	var=$(printf "%03d" "$i")
# 	echo $var
#             #下载mgex brdm格式的广播星历
#         # if [ -f brdm${var}0.19p ] && [ -s brdm${var}0.19p ] 
#         # then
#         #     echo "brdm${var}0.19p aready downloaded!"
#         # else
#         #     wget ftp://cddis.nasa.gov/pub/gps/data/campaign/mgex/daily/rinex3/2019/${var}/19p/brdm${var}0.19p.Z
#         # #    wget ftp://igs.gnsswhu.cn:21/pub/gnss/mgex/daily/rinex3/2019/${var}/19p/brdm${var}0.19p.Z
#         #     gunzip brdm${var}0.19p.Z
#         # fi
#             wget ftp://cddis.nasa.gov/pub/gps/data/campaign/mgex/daily/rinex3/2019/${var}/19p/brdm${var}0.19p.Z
#             gunzip brdm${var}0.19p.Z
#             mv brdm${var}0.19p EPH/
#             wget ftp://cddis.gsfc.nasa.gov/pub/gps/data/daily/2019/${var}/19p/BRDC00IGS_R_2019${var}0000_01D_MN.rnx.gz
#             gunzip BRDC00IGS_R_2019${var}0000_01D_MN.rnx.gz
#             mv BRDC00IGS_R_2019${var}0000_01D_MN.rnx  EPH/brdc${var}0.19p

#   #下载观测数据
# 	for station in DARW00AUS GATT00AUS WYRL00AUS DODA00AUS; do 
#          #LEIJ MIZU POTS SGOC SUTM ULAB URUM WUH200CHN JFNG00CHN PERT00AUS NNOR00AUS
#         #下载MGEX 文件
#         filename=${station}_R_2019${var}0000_01D_30S_MO
#         lowname=$station
#         # if [ -f ${filename}.19o ] && [ -s ${filename}.19o ] 
#         # then
#         # 	echo "${filename}.19o aready downloaded!"
#         # else
#           wget ftp://cddis.nasa.gov/pub/gps/data/daily/2019/${var}/19d/${filename}.crx.gz

#           gunzip ${filename}.crx.gz
#           crx2rnx -f ${filename}.crx
#           rm ${filename}.crx
#           mv ${filename}.rnx MGEX/${lowname}${var}0.19o

#         # fi 
        
#     done

# wget -r -l1 --no-parent -A.crx.gz ftp://ftp.ga.gov.au/geodesy-outgoing/gnss/data/daily/2019/19${var}/
# # mv *.crx.gz AUSCORS
# # -r -np -nH
# # download HK CORS data
# declare -l lowname



# function to_lowercase()
# {
#     LOWER_CASE=$(echo ${1} | tr '[A-Z]' '[a-z]')
#     return ${LOWER_CASE}
# }
 
# function to_uppercase()
# {
#     UPPER_CASE=$(echo ${1} | tr '[a-z]' '[A-Z]')
#     echo ${UPPER_CASE}
# }


# for station in HKSL HKWS; do done
    station1=HKSL
    station2=HKWS
    station1low=hksl
    station2low=hkws
    # for day in {130..229}; do
    for day in {228..229}; do

        doy=$(printf "%03d" "$day")
        for hour in {14..23}; do

              filename=${station1}00HKG_R_2022${doy}${hour}00_01H_01S_MO
              if [ -f ${filename}.rnx ] && [ -s ${filename}.rnx ] 
              then
                echo "${filename}.crx.gz aready downloaded!"
              else
              wget ftp://ftp.geodetic.gov.hk/rinex3/2022/${doy}/${station1low}/1s/${filename}.crx.gz
              gunzip ${filename}.crx.gz
              crx2rnx -f ${filename}.crx
              fi

              filename=${station2}00HKG_R_2022${doy}${hour}00_01H_01S_MO
              if [ -f ${filename}.rnx ] && [ -s ${filename}.rnx ] 
              then
                echo "${filename}.crx.gz aready downloaded!"
              else
              wget ftp://ftp.geodetic.gov.hk/rinex3/2022/${doy}/${station2low}/1s/${filename}.crx.gz
              gunzip ${filename}.crx.gz
              crx2rnx -f ${filename}.crx
            fi
        done
    done
rm *.crx
# for day in {130..229}; do
#   doy=$(printf "%03d" "$day")
#   wget ftp://igs.ign.fr/pub/igs/data/2022/${doy}/BRDC00IGN_R_2022${doy}0000_01D_MN.rnx.gz
#   gunzip BRDC00IGN_R_2022${doy}0000_01D_MN.rnx.gz
# done